home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10092 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: EU.net!sun4nl!xs4all!falstaff
  2. From: falstaff@xs4all.nl (Falstaff)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: NEwbie: How to return a multi-dimensional array from function?
  5. Date: 15 Mar 1996 15:53:07 GMT
  6. Organization: XS4ALL, networking for the masses
  7. Message-ID: <4ic3p3$cl5@news.xs4all.nl>
  8. References: <4hp273$8bu@news.xs4all.nl> <31404CE9.1A4A@mc.net> <mjs.826298629@hubcap> <4ib78s$6gv@news.bridge.net>
  9. NNTP-Posting-Host: xs1.xs4all.nl
  10. X-Newsreader: NN version 6.5.0 #666 (NOV)
  11.  
  12. psycho@bridge.net (Gary Thompson) writes:
  13.  
  14. >>Two things: (1) If you are going to use the value of tmp outside of Foo(),
  15. >>then you need to declare
  16. >>    static tmp[10][5];
  17. >>Otherwise the storage may disappear when you return from Foo().
  18.  
  19. >No, declaring it as static will only retain the value in the foo() function, if
  20. >you call it more than once.  You CANNOT use a value declared in a subfunction in
  21. >MAIN.  You would have to remove both TMP declarations from MAIN and FOO and
  22. >declare the thing globally outside of main.
  23.  
  24. WRONG!!!
  25.  
  26. If you declare a function
  27.  
  28. int *demo(void)
  29. {  static int n=0;
  30.    n++;
  31.    return &n;
  32. }
  33.  
  34. the caller can use the static variable until the next time your function
  35. is called.  This is how the standard library function tmpnam() returns,
  36. for example.
  37.  
  38. Frank
  39. --
  40. The famous GIICM now on line:  http://www.xs4all.nl/~falstaff/GIICM.html
  41. ------------------------------------------------------------------------
  42. Frank A. Vorstenbosch        +31-(70)-355 5241        falstaff@xs4all.nl
  43.